package com.ruoyix.weblog.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyix.weblog.domain.bo.BlogVideoCatalogBo;
import com.ruoyix.weblog.domain.vo.BlogVideoCatalogVo;
import com.ruoyix.weblog.service.IBlogVideoCatalogService;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyix.common.annotation.RepeatSubmit;
import com.ruoyix.common.annotation.Log;
import com.ruoyix.common.core.controller.BaseController;
import com.ruoyix.common.core.domain.PageQuery;
import com.ruoyix.common.core.domain.R;
import com.ruoyix.common.core.validate.AddGroup;
import com.ruoyix.common.core.validate.EditGroup;
import com.ruoyix.common.core.validate.QueryGroup;
import com.ruoyix.common.enums.BusinessType;
import com.ruoyix.common.utils.poi.ExcelUtil;

import com.ruoyix.common.core.page.TableDataInfo;

/**
 * 视频集管理
 *
 * @author ruoyi
 * @date 2024-09-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/weblog/BlogVideoCatalog")
public class BlogVideoCatalogController extends BaseController {

    private final IBlogVideoCatalogService iBlogVideoCatalogService;

    /**
     * 查询视频集管理列表
     */
    @SaCheckPermission("weblog:BlogVideoCatalog:list")
    @GetMapping("/list")
    public TableDataInfo<BlogVideoCatalogVo> list(BlogVideoCatalogBo bo, PageQuery pageQuery) {
        return iBlogVideoCatalogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出视频集管理列表
     */
    @SaCheckPermission("weblog:BlogVideoCatalog:export")
    @Log(title = "视频集管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BlogVideoCatalogBo bo, HttpServletResponse response) {
        List<BlogVideoCatalogVo> list = iBlogVideoCatalogService.queryList(bo);
        ExcelUtil.exportExcel(list, "视频集管理", BlogVideoCatalogVo.class, response);
    }

    /**
     * 获取视频集管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("weblog:BlogVideoCatalog:query")
    @GetMapping("/{id}")
    public R<BlogVideoCatalogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iBlogVideoCatalogService.queryById(id));
    }

    /**
     * 新增视频集管理
     */
    @SaCheckPermission("weblog:BlogVideoCatalog:add")
    @Log(title = "视频集管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BlogVideoCatalogBo bo) {
        return toAjax(iBlogVideoCatalogService.insertByBo(bo));
    }

    /**
     * 修改视频集管理
     */
    @SaCheckPermission("weblog:BlogVideoCatalog:edit")
    @Log(title = "视频集管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BlogVideoCatalogBo bo) {
        return toAjax(iBlogVideoCatalogService.updateByBo(bo));
    }

    /**
     * 删除视频集管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("weblog:BlogVideoCatalog:remove")
    @Log(title = "视频集管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iBlogVideoCatalogService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

}
